<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/21
 * Time: 17:29
 */

namespace Common\Logic;

use Common\Model\UserModel;

class UserLogic extends BaseLogic
{

    private $user_mod = '';

    function __construct()
    {
        parent::__construct();
        $this->user_mod = new UserModel('user');
    }

    /**
     *用户列表
     */
    public function getUserList()
    {
        $ret = $this->user_mod->getList();
        return $ret;
    }


    /**
     * 个人中心修改用户数据详情
     */
    public function getUserInfo()
    {
        $vid = I('vid');
        $pic_mod=new UserModel('user_idcard_img');
        $where['vid']=$vid;
        $field='vid,mobile,truename,id_card,province,city,ismarry,sex,ctime,address,degree,residence_time,work_verify';
        $user=  $this->user_mod->getOne($where,$field);
        $ret['user_pic']=$pic_mod->getOne($where,'photo,photo1,photo2,front,behind');
        $user['ctime'] = date('Y-m-d H:i', $user['ctime']);
        $user['card_address'] = $user['province'] . $user['city'];
//        $user['u_mobile']=$user['mobile'];
      $user['u_mobile']= get_mobile($user['mobile']);
        switch ($user['work_verify']){
            case 0:  $user['work_verify']='未认证';break;
            case 1:  $user['work_verify']='认证';break;
            case 2:  $user['work_verify']='待修改';break;
        }
        $ret['user']=$user;
        return $ret;
    }

    /**
     * 个人中心修改用户保存
     */
    public function setUserSave(){

        if(!I('vid') || I('vid')==null){
            return $this->ReturnMsg('1002','请上传vid','');
        }
        $param=[];
        //需要修改的字段筛选
        foreach ($_POST as  $k=>$v){
            if(!empty($_POST[$k]) && !empty($v)){
                switch ($k){
                    case 'user_name':  $param['truename'] =$v;  break;
                    case 'select_sex':  $param['sex'] =$v;  break;
                    case 'select_marry':  $param['ismarry'] =$v;  break;
                    case 'degree':  $param['degree'] =$v;  break;
                    case 'id_card':  $param['id_card'] =$v;  break;
                    case 'live_address':  $param['address'] =$v;  break;
                    case 'live_time':  $param['residence_time'] =$v;  break;
                }
            }
        }
        if(!empty($param)){
            $where['vid']=I('vid');
            if($this->user_mod->setSave($where,$param)){
                add_log('修改用户信息'.I('vid'));
                return $this->ReturnMsg('1001','修改成功',$param);
            }else{
                return $this->ReturnMsg('1002','修改失败',$param);
            }
        }
    }


}